/*! ******************************************************************************
 *
 * Created on 2022年3月5日
 *
 * Copyright(c) YuZhou Big Data Laboratory CO.,Ltd, 2022.  All rights reserved.
 *
 *******************************************************************************
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ******************************************************************************/
package org.yzbdl.lanius.ui.spoon.bottom;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;

/**
 * @author hs@yzbdl.ac.cn
 *
 */
public class StateButtonItem extends ToolItem {

	private StateButtonItemAdapter stateBarBtnAdapter;

	public StateButtonItem(ToolBar parent, StateButtonItemAdapter stateBarBtnAdapter) {
		this(parent, SWT.PUSH);
		this.setToolTipText(stateBarBtnAdapter.getStateBarBtnName());

		Image image = stateBarBtnAdapter.getImage();
		ImageData imageData = image.getImageDataAtCurrentZoom();
		imageData.transparentPixel = imageData.palette.getPixel(new RGB(255, 255, 255));
		image = new Image(parent.getDisplay(), imageData);
		this.setImage(image);

		this.stateBarBtnAdapter = stateBarBtnAdapter;

		this.addSelectionListener(new SelectionListener() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				StateButtonItem.this.stateBarBtnAdapter.onStateBarBtnClick();
			}

			@Override
			public void widgetDefaultSelected(SelectionEvent e) {
			}
		});

		new ToolItem(parent, SWT.SEPARATOR);
	}

	private StateButtonItem(ToolBar parent, int style) {
		super(parent, style);
	}

	@Override
	protected void checkSubclass() {
	}

}
